package com.jiang.demo.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ---------------------------------------------------------------------------------------------------------------
 * - 2024-06-01 15:24 - jiangshaoneng -
 * ---------------------------------------------------------------------------------------------------------------
 * -      ██╗██╗ █████╗ ███╗   ██╗ ██████╗ ███████╗██╗  ██╗ █████╗  ██████╗ ███╗   ██╗███████╗███╗   ██╗ ██████╗
 * -      ██║██║██╔══██╗████╗  ██║██╔════╝ ██╔════╝██║  ██║██╔══██╗██╔═══██╗████╗  ██║██╔════╝████╗  ██║██╔════╝
 * -      ██║██║███████║██╔██╗ ██║██║  ███╗███████╗███████║███████║██║   ██║██╔██╗ ██║█████╗  ██╔██╗ ██║██║  ███╗
 * - ██   ██║██║██╔══██║██║╚██╗██║██║   ██║╚════██║██╔══██║██╔══██║██║   ██║██║╚██╗██║██╔══╝  ██║╚██╗██║██║   ██║
 * - ╚█████╔╝██║██║  ██║██║ ╚████║╚██████╔╝███████║██║  ██║██║  ██║╚██████╔╝██║ ╚████║███████╗██║ ╚████║╚██████╔╝
 * -  ╚════╝ ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝╚═╝  ╚═══╝ ╚═════╝
 * ---------------------------------------------------------------------------------------------------------------
 * 服务端接口返回包装类, 用于返回接口数据, 异常数据等
 * [0: 成功]
 * [-1:失败]
 * [小于 -1000 业务异常, 客户端直接提示即可]
 * [大于  1000 需要客户端做特殊处理, 如:跳转到指定页面等]
 * ---------------------------------------------------------------------------------------------------------------
 */
@ApiModel(value = "ApiResponse")
@Data
@AllArgsConstructor
public class MSG<T> {

    private final static Logger logger = LoggerFactory.getLogger(MSG.class);

    @ApiModelProperty("状态码")
    private int code;

    @ApiModelProperty("描述信息")
    private String message;

    @ApiModelProperty("数据")
    private T data;

    // 状态码
    private final static int SUCCESS = 200;
    private final static int FAIL = -1;


    public static <T> MSG<T> SUCCESS() {
        return new MSG<>(SUCCESS, "操作成功", null);
    }

    public static <T> MSG<T> SUCCESS(String message) {
        return new MSG<>(SUCCESS, message, null);
    }

    public static <T> MSG<T> SUCCESS(T t) {
        return new MSG<>(SUCCESS, "操作成功", t);
    }


    public static <T> MSG<T> FAIL() {
        return new MSG<>(FAIL, "操作失败", null);
    }

    public static <T> MSG<T> FAIL(String message) {
        return new MSG<>(FAIL, message, null);
    }


    public static <T> MSG<T> WARN(int code, String message, T t) {
        //if(code < 0) logger.warn("[WARN ResponseEntity 建议大于等于 1000] code:"+code+",message:"+message);
        return new MSG<>(code, message, t);
    }

    public static <T> MSG<T> ERROR(int code, String message) {
        //if(code > 0) logger.warn("[ERROR ResponseEntity 建议小于等于 -1000] code:"+code+",message:"+message);
        return new MSG<>(code, message, null);
    }
}
